/*
 *     UserServiceImpl.java  Copyright (c) 2021. cc01cc. All rights reserved.
 *
 *     This file is part of e-commerce.
 *
 *     e-commerce is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Affero General Public License as published
 *     by the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     e-commerce is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Affero General Public License for more details.
 *
 *     You should have received a copy of the GNU Affero General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package service;

import dao.BasicDao;
import dao.UserDao;
import dao.UserDaoImpl;
import pojo.User_register;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author cc01cc
 */
//    UserServiceImpl 继承接口 UserService
public class UserServiceImpl implements UserService{
    private UserDao userDao;

    public UserServiceImpl(){
        userDao = new UserDaoImpl();
    }
//  使用传入的信息，登录账户，无账户则返回无
    @Override
    public User_register login(String userName, String password) {
        Connection connection = null;
        User_register user = null;
//        使用dao进行数据库的查询操作
        try{
            connection = BasicDao.getConnection();
            user = userDao.getLoginUser(connection, userName);
//            System.out.println(user.getUser_name());
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            BasicDao.closeResource(connection,null,null);
        }
        if(user.getUser_pwd().equals(password)){
            return user;
        }else {
            return null;
        }
    }
}
